package director;

import structural.proxy.AbstractObject;
import structural.proxy.MyInvocationHandler;
import structural.proxy.ProxyObject;
import structural.proxy.RealObject;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class ProxyDirector {

    public static void main(String[] args) {
        //构建真实对象
        AbstractObject target = new RealObject();
        //构建代理对象并代理真实对象
        AbstractObject proxy = new ProxyObject(target);
        proxy.doSomething();

        ///////////////////动态代理///////////////////////////
        InvocationHandler ih = new MyInvocationHandler(target);
        AbstractObject proxy0 = (AbstractObject) Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),ih);
        proxy0.doSomething();
    }
}
